//
//  BGFourCell.m
//  bigMall
//
//  Created by ios on 16/9/18.
//  Copyright © 2016年 thinklev. All rights reserved.
//

#import "BGFourCell.h"
#import "BGReadStepTwoModel.h"
@interface BGFourCell () <UITextFieldDelegate> {
    
    UILabel *titleLab;
    UITextField *textFiled;
    
}
@end

@implementation BGFourCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier default_value:(NSArray *)default_valueArr {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
       
        BGReadStepTwoModelArrDetail *model = default_valueArr.firstObject;
        
        //修饰线
        UIView *v1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 1)];
        v1.backgroundColor = dockwhite_;
        [self.contentView addSubview:v1];
        
        titleLab = [[UILabel alloc] initWithFrame:CGRectMake(21, 10, 100, 21)];
        titleLab.font = [UIFont systemFontOfSize:16];
        titleLab.text = self.titleText;
        CGSize labSize = [titleLab.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:titleLab.font,NSFontAttributeName, nil]];
        titleLab.height = labSize.height;
        titleLab.width = labSize.width;
        [self.contentView addSubview:titleLab];
        
        textFiled = [[UITextField alloc] initWithFrame:CGRectMake(titleLab.right + 10, 10, 100, 21)];
        textFiled.delegate = self;
        textFiled.font = [UIFont systemFontOfSize:14];
        
        [textFiled addTarget:self action:@selector(change:) forControlEvents:UIControlEventEditingDidEnd];
        textFiled.placeholder = @"请填写";
        textFiled.text = model.value;
        [self.contentView addSubview:textFiled];
        
    }
    
    return self;
    
}
- (void)setTitleText:(NSString *)titleText {
    titleLab.text = [NSString stringWithFormat:@"%@：",titleText];
}
- (void)layoutSubviews {
    
    //设置标题的大小
    CGSize biaotiSize = [titleLab.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:titleLab.font,NSFontAttributeName, nil]];
    titleLab.width = biaotiSize.width;
    titleLab.height = biaotiSize.height;
    
    textFiled.frame = CGRectMake(titleLab.right + 10, 10, 100, 21);
    
}
//- (void)textFieldDidEndEditing:(UITextField *)textField {
//    
//    if ([_delegate respondsToSelector:@selector(filedValueChange:index:)]) {
//        [_delegate filedValueChange:textField index:self.attr_id];
//    }
//    
//}
- (void)change:(UITextField *)filed {
    
    if ([_delegate respondsToSelector:@selector(filedValueChange:index:)]) {
        [_delegate filedValueChange:filed index:self.attr_id];
    }
    
}

@end
